package com.xcfw.dorm.seviceimpl.dormassistant;

import com.xcfw.dorm.entity.DormAssistan;
import com.xcfw.dorm.entity.Duty;
import com.xcfw.dorm.exception.ServiceException;
import com.xcfw.dorm.mapper.DutyMapper;
import com.xcfw.dorm.sevice.BaseService;
import com.xcfw.dorm.sevice.ZSGCService;
import com.xcfw.dorm.util.DormUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: Dorm
 * @description: 值周
 * @author: Bruse Queen
 * @create: 2018-04-08 10:25
 **/
@Service("dutyServiceImpl")
public class DutyServiceImpl extends BaseService implements ZSGCService {
    @Autowired
    private DutyMapper mapper;

    @Override
    public void add(Object o) {
        Duty param = (Duty) o;
        param.setUuid(DormUtil.getUUID());
        zsgcStatus = mapper.insertSelective(param);
        if (1 != zsgcStatus) {
            throw new ServiceException("新增值周信息失败！");
        }
    }

    @Override
    public void delete(Integer id) {
        zsgcStatus = mapper.deleteByPrimaryKey(id);
        if (1 != zsgcStatus) {
            throw new ServiceException("删除值周信息失败！");
        }
    }

    @Override
    public void update(Object o) {
        Duty param = (Duty) o;

        Duty temp = mapper.selectByPrimaryKey(param.getId());
        if (temp != null) {
            if (param.equals(temp)) {
                throw new ServiceException("您未修改任何信息！");
            }
        }

        zsgcStatus = mapper.updateByPrimaryKeySelective(param);
        if (1 != zsgcStatus) {
            throw new ServiceException("修改值周信息失败！");
        }
    }

    @Override
    public Object select(Object o) {
        List<Duty> list = mapper.selectActionSql(null);
        if (list.size() == 0) {
            throw new ServiceException("暂无相关数据！");
        }
        return list;
    }
}
